<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <canvas id="c" width="600" height="400" style="border: 1px solid #ccc"></canvas>

        <script>
            const cnv = document.getElementById('c')
            const ctx = cnv.getContext('2d')

            let index = 0
            function render() {
                ctx.clearRect(0, 0, 600, 400)
                index += 0.01
                if (index >= 1) {
                    index = 0
                }

                let linearGradient = ctx.createLinearGradient(100, 200, 400, 500)
                linearGradient.addColorStop(0, 'red')
                linearGradient.addColorStop(index, '#ffcccc')
                linearGradient.addColorStop(1, 'blue')
                ctx.fillStyle = linearGradient
                ctx.fillRect(100, 200, 300, 300)
                requestAnimationFrame(render)
            }
            requestAnimationFrame(render)
        </script>
    </body>
</html>
